<template>
  <div style="text-align: center;">
    <h1 style="color: #fff;">密码修改</h1>
    <el-col :span="24" class="toolbar">
      <el-form style="width:200px;">
        <el-form-item>
          <el-input v-model="oldPassword" type="password" placeholder="旧密码" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="password" type="password" placeholder="新密码" />
        </el-form-item>
        <el-form-item>
          <el-input v-model="confirmPassword" type="password" placeholder="确认新密码" />
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="modifyPassword">确认修改</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </div>
</template>

<script>
export default {
  name: "passwordModify",
  data() {
    return {
      oldPassword: "",
      password: "",
      confirmPassword: ""
    };
  },
  methods: {
    modifyPassword: function() {
      this.$api.user.modifyPassword({
        oldPassword: this.oldPassword,
        password: this.password,
        confirmPassword: this.confirmPassword
      }).then(res => {
        if(!res) {
          return;
        }

        this.$router.push("/");
        this.$message({
              type: "success",
              message: "密码修改成功，请重新登录！"
            });
      });
    }
  }
};
</script>

<style scoped>
.el-form-item {
  text-align: center;
}
</style>
